package com.szl.group.template;

/**
 * 结果处理工具类
 */
public class ResultUtils {

    /**
     * 构建成功结果
     * @param <T>
     * @return
     */
    public static <T> Result<T> buildSuccess(){
        return buildSuccess(null);
    }
    /**
     * 构建成功结果
     * @param data
     * @param <T>
     * @return
     */
    public static <T> Result<T> buildSuccess(T data){
        Result<T> result = new Result<T>();
        result.setCode(ResultCodeEnum.OK.getCode());
        result.setMsg(ResultCodeEnum.OK.getMessage());
        result.setData(data);
        return result;
    }

    /**
     * 构建失败结果
     * @param resultCodeEnum
     * @return
     */
    public static <T> Result<T> buildFailed(ResultCodeEnum resultCodeEnum){
        return buildFailed(resultCodeEnum.getCode(),resultCodeEnum.getMessage());
    }

    /**
     * 构建失败结果
     * @param resultCodeEnum
     * @param data
     * @return
     */
    public static <T> Result<T> buildFailed(ResultCodeEnum resultCodeEnum,Object data){
        return buildFailed(resultCodeEnum.getCode(),resultCodeEnum.getMessage(),data);
    }

    /**
     * 构建失败结果
     * @param errorCode
     * @param errorMsg
     * @param <T>
     * @return
     */
    public static <T> Result<T> buildFailed(String errorCode,String errorMsg){
        return buildFailed(errorCode,errorMsg,null);
    }

    /**
     * 构建失败结果
     * @param errorCode
     * @param errorMsg
     * @param data
     * @return
     */
    public static <T> Result<T> buildFailed(String errorCode,String errorMsg,Object data){
        Result result = new Result();
        result.setCode(errorCode);
        result.setMsg(errorMsg);
        result.setData(data);
        return result;
    }
}
